package com.faradel.pharmapp.dao;

import java.util.List;
import java.util.Map;

import org.faradel.pharmapp.entities.PatientOrder;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

@Component("patientOrderDaoImpl")
public class PatientOrderDaoImpl extends GenericDAOImpl<PatientOrder, Integer> implements PatientOrderDAO
{

    @SuppressWarnings("unchecked")
    @Override
    public List<PatientOrder> findByColumn(Map<String, String> map)
    {
        Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(PatientOrder.class);
        for (Map.Entry<String, String> mapEntry : map.entrySet())
        {
            if (mapEntry.getKey().equalsIgnoreCase("patient_id"))
            {
                criteria.add(Restrictions.eq(mapEntry.getKey(), Integer.parseInt(mapEntry.getValue())));
            }
            else
                criteria.add(Restrictions.eq(mapEntry.getKey(), mapEntry.getValue()));
        }
        return criteria.list();
    }

}
